$(function(){
    initSubmitEvent();
});

function initSubmitEvent(){
    $('#submitForm').validate({
        debug: false, //调试模式取消submit的默认提交功能
        focusInvalid: false,
        onkeyup: false,
        submitHandler: function(form){
            if (typeof jQuery.data(this, "disabledOnSubmit") == 'undefined') {
                jQuery.data(this, "disabledOnSubmit", {submited : true});
                var flag = $('input[name="status"]:checked').val();
                var tipsMessage = (flag ==="2")?"请确认是否审核通过?":"请确认是否审核不通过?";
                if (confirm(tipsMessage)) {
                    form.submit();
                } else {
                    jQuery.removeData(this,"disabledOnSubmit");
                }
            } else {
                // repeat submit ignore;
            }
        },
        success:function(element){
        },
        errorPlacement : function(error, element) {
            if(error.text()){
                if(element.next("span[class='error red']").size() == 0){
                    element.after("<span class='error red'>" + error.text() +"</span>");
                }else{
                    element.next("span[class='error red']").text(error.text());
                }
            }else{
                element.next("span[class='error red']").remove();
            }
        },
        rules:{
            memo:{
                conditionRequired:(function(){
                    var flag = $('input[name="status"]:checked').val();
                    if(flag != "2"){
                        //审核不通过，备注信息必填
                        var remark = $("[name=memo]").val();
                        remark = remark.replace(/(^\s*)|(\s*$)/g, '');//去除空格
                        if( remark == undefined || remark == "" || remark == null){
                            return true;
                        }
                    }
                    return false;
                })
            },
            fundMoney:{
                conditionRequired:(function(){
                    var flag = $('input[name="status"]:checked').val();
                    if(flag != "1"){
                        //审核通过，退还金额必填
                        var returnFundAmount = $("[name=fundMoney]").val();
                        returnFundAmount = returnFundAmount.replace(/(^\s*)|(\s*$)/g, '');//去除空格
                        if( returnFundAmount == undefined || returnFundAmount == "" || returnFundAmount == null){
                            return true;
                        }
                    }
                    return false;
                })
            },
            returnQuoteAmount:{
                conditionRequired:(function(){
                    var flag = $('input[name="status"]:checked').val();
                    if(flag != "1"){
                        //审核通过，退还配额数量必填
                        var returnQuoteAmount = $("[name=returnQuoteAmount]").val();
                        returnQuoteAmount = returnQuoteAmount.replace(/(^\s*)|(\s*$)/g, '');//去除空格
                        if( returnQuoteAmount == undefined || returnQuoteAmount == "" || returnQuoteAmount == null){
                            return true;
                        }
                    }
                    return false;
                })
            },
            quotaId:{
                conditionRequired:(function(){
                    var flag = $('input[name="status"]:checked').val();
                    if(flag != "1"){
                        //审核通过，配额类型必填
                        var quotaId = $("[name=quotaId]").val();
                        quotaId = quotaId.replace(/(^\s*)|(\s*$)/g, '');//去除空格
                        if( quotaId == undefined || quotaId == "" || quotaId == null){
                            return true;
                        }
                    }
                    return false;
                })
            }
        },
        messages:{
            memo:{conditionRequired:"审核不通过,备注信息必填"},
            fundMoney:{conditionRequired:"审核通过，退款金额必填"},
            returnQuoteAmount:{conditionRequired:"审核通过，返还配额必填"},
            quotaId:{conditionRequired:"审核通过，配额类型必填"}
        }
    });
}

function show() {
    $('.dynamic.pass').show();
}

function hide() {
    $('.dynamic.pass').hide();
}